#define _CRT_SECURE_NO_WARNINGS 1


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int Func(int n)
{
	int sum = 0;

	while (n)
	{
		sum += n % 10;
		n /= 10;
	}

	return sum;
}

int main()
{
	int n = 0;
	scanf("%d", &n);

	while (n--)
	{
		char arr[101] = { 0 };
		scanf("%s", arr);
		char str[10] = { 0 };
		int count[6] = { 0 }, index = 0;

		for (int i = 0; i < strlen(arr); i++)
		{
			if (i % 6 == 0 && i != 0)
			{
				for (int j = 0; j < 6; j++)
				{
					count[j] += str[j];
				}

				for (int j = 0; j < 6; j++)
				{
					str[j] = '\0';
				}
				index = 0;
			}
			str[index++] = arr[i];
		}
		for (int j = 0; j < strlen(str); j++)
		{
			count[j] += str[j];
		}

		for (int i = 0; i < 6; i++)
		{
			int ret = Func(count[i]);

			while (ret % 10 != ret)
			{
				ret = Func(ret);
			}

			printf("%d", ret);
		}

		printf("\n");
	}

	return 0;
}